# 列表概述
list_example = [1, 'xiaowang', 'a', [2, 'abc']]
print(list_example[0])
print(list_example[1])
print(list_example[2])
print(list_example[3])
print('*'*15)
print(list_example[3][0])
print(list_example[3][1])
print(list_example[3][1][2])

print('-'*15)
# for 循环遍历列表
list_example = [1, 'xiaowang', 'a', [2, 'abc']]
for i in list_example:
    print(i)

print('-'*15)
# whle 循环
list_example = [1, 'xiaowang', 'a', [2, 'abc']]
length = len(list_example)
i = 0
while i < length:
    print(list_example[i])
    i += 1

print('-'*15)
# append
names_list = ['xiaowang', 'xiaozhang', 'xiaohua']
for i in names_list:
    print(i)
print('-'*17)
names_list.append(input('输入添加姓名：'))
for i in names_list:
    print(i)

print('-'*15)
# extend
list_one = [1, 2]
list_two = [3, 4]
list_one.extend(list_two)
print(list_one)
list_one.extend(list_two)
print(list_one)

print('-'*15)
# insert
list_one = [1, 2]
list_one.insert(1, 3)
print(list_one)

print('-'*15)
# 在列表中查找元素
names_list = ['xiaowang', 'xiaozhang', 'xiaohua']
find_name = input("输入要查找的名称：")
if find_name in names_list:
    print(True)
else: print(False)

print('-'*15)
# 修改元素
names_list = ['xiaowang', 'xiaozhang', 'xiaohua']
print('-------修改前 name_list 数据-------')
for i in names_list:
    print(i, end = ' ')
names_list[0] = 'wang'

print('\n-------修改后 name_list 数据-------')
for i in names_list:
    print(i, end = ',')

print('\n')

print('-' * 15)
# del
number_list = [1, 2, 3, 4, 5]
del number_list[0]
for i in number_list:
    print(i, end=' ')

print()

print('-' * 15)
# pop
number_list = [1, 2, 3, 4, 5]
number_list.pop()
for i in number_list:
    print(i, end=' ')

print()

print('-' * 15)
# remove
number_list = [1, 2, 3, 4, 5]
number_list.remove(3)
for i in number_list:
    print(i, end=' ')

print()

print('-' * 15)
# sort reverse
list_demo = [1, 9, 4, 7]
list_demo.reverse()
print(list_demo)
list_demo.sort()
print(list_demo)
list_demo.sort(reverse=True)
print(list_demo)

print('-'*15)
# 案例
import random
# 定义一个列表用来保存 3 个办公室
offices = [[], [], []]
# 定义一个列表用来存储 8 位老师的名字
names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
for name in names:
    index = random.randint(0,2)
    offices[index].append(name)

i = 1
for tmp in offices:
    print("办公室 %d 的人数为：%d"%(i, len(tmp)))
    i += 1
    for name in tmp:
        print('%s'%name,end = ' ')
    print('-'*20)
